<template>
  <div class="home">
    <el-container>
      <el-aside width="200px">
        <el-menu
          :default-active="'1-1'"
          class="el-menu-vertical-demo"
          background-color="#545c64"
          text-color="#fff"
          active-text-color="#ffd04b"
          :unique-opened="true"
          :router="true"
        >
          <div class="logo"></div>
          <el-submenu :index="first.id+''" v-for="first in menusList" :key="first.id">
            <template slot="title">
              <i class="el-icon-location"></i>
              <span>{{first.authName}}</span>
            </template>
            <el-menu-item :index="'/home/'+secend.path" v-for="secend in first.children" :key="secend.id">
              <template slot="title">
                <i class="el-icon-location"></i>
                <span>{{secend.authName}}</span>
              </template>
            </el-menu-item>
          </el-submenu>
        </el-menu>
      </el-aside>
      <el-container>
        <el-header>
          <el-button type="primary" style="background-color:#606266" class="myicon myicon-menu"></el-button>
          <div class="dwxtitle">后台管理系统</div>
          <el-button type="info" round>退出</el-button>
        </el-header>
        <el-main>
          <router-view></router-view>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>
<script>
import { menusList } from '@/api/right_api.js'
export default {
  data () {
    return {
      menusList: ''
    }
  },
  mounted () {
    // 不同的角色能够实现的功能是不一样的，
    // 功能体现在左侧菜单的选项上。
    // 意味着如果没有某个功能，
    // 最好不要显示某个菜单项
    menusList()
      .then(res => {
        // console.log(res)
        if (res.data.meta.status === 200) {
          this.menusList = res.data.data
        }
      })
      .catch(err => {
        console.log(err)
      })
  },
  methods: {
    handleOpen (key, keyPath) {
      console.log(key, keyPath)
    },
    handleClose (key, keyPath) {
      console.log(key, keyPath)
    }
  }
}
</script>
<style lang="less" scoped>
.home {
  height: 100%;
  .el-menu-admin:not(.el-menu--collapse) {
    width: 200px;
    min-height: 400px;
  }
  .el-container {
    height: 100%;
  }
  .el-aside {
    background-color: #545c64;
    height: 100vh;
  }
  .el-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background-color: #545c64;
  }
  .logo {
    height:60px;
    background: url(../assets/logo.png);
    background-size: cover;
    background-color: #fff;
  }
  .toggle-btn {
    padding: 0 15px;
    margin-left: -20px;
    font-size: 36px;
    color: white;
    cursor: pointer;
    line-height: 60px;
    &:hover {
      background-color: #4292CF;
    }
  }
  .system-title {
    font-size: 28px;
    color: white;
  }
  .welcome{
    color: white;
  }
}
.dwxtitle{
  font-size: 30px;
  color: #fff;
  font-weight: 600;
  letter-spacing:10px
}
</style>
